var module = angular.module('app.HuodongController', []);

module.controller('HuodongController',function ($scope, ConfigModule, $http, $location,$ionicPopup,API,$window,$base64 ) {

    $scope.pay_type = {};
    $scope.pay_type.pay_type = 1;
    $scope.choose = "unchoosed";
    $scope.chooses = false;

    $scope.backfn = function(){
        if($scope.choose == "choosed"){
            $scope.choose = "unchoosed";
        }else{
            $scope.choose = "choosed";
        }
    }

    $scope.alert = function(msg){
        var confirm = $ionicPopup.confirm({
            title: '消息提示',
            template : msg,
            buttons: [
                {
                    text: '<b>确定</b>',
                    type: 'button-positive'
                }
            ]
        });
    };
    $scope.pay = function(vip_type){
        if($scope.choose == "unchoosed"){
            return $scope.alert('请选择同意服务协议');
        }
        var confirm = $ionicPopup.confirm({
            title: '选择支付方式',
            templateUrl: 'tpl/public/check_pay2.html',
            okText : '确定',
            cancelText : '取消',
            scope : $scope
        });
        confirm.then(function(res) {
            if(res) {
                if($scope.pay_type.pay_type){
                    API.vipRecharge({
                        vip_type : vip_type,
                        pay_type : $scope.pay_type.pay_type
                    },function(err,result){
                        if(result.status == 200){
                            if($scope.pay_type.pay_type == 1){
                                var wepay = result.data;
                                wepay.vip = true;
                                var info = angular.toJson(wepay);
                                console.log('http://www.hjfzqy.cn/index.html#/pay?info='+$base64.encode(info));
                                $window.location.href='http://www.hjfzqy.cn/index.html#/pay?info='+$base64.encode(info);
                            }else{
                                $scope.alert('支付成功');
                                $state.reload();
                            }
                        }else{
                            $scope.alert(result.message);
                        }
                    });
                }
            }
        });

    };

});



module.controller('CouponController',function ($scope, API, $stateParams ,$ionicPopup) {

    $scope.$emit('hideNav',false);
    var status = $scope.status = $stateParams.status;
    $scope.status0 = $scope.status1 = 0;
    switch ($stateParams.status){
        case '0':
            $scope.status0 = 'active';
            break;
        case '1':
            $scope.status1 = 'active';
            break;
        default :
            $scope.status1 = 'active';
            $stateParams.status = 1;
            break;
    }
    API.getCouponList({
        status : status
    },function(err,result){
        if(result.status == 200){
            $scope.couponlist = result.data.list;
            $scope.status1 = result.data.num1;
            $scope.status0 = result.data.num2;
        }else{
            $scope.alert(result.message);
        }
    });

    $scope.alert = function(msg){
        var confirm = $ionicPopup.confirm({
            title: '消息提示',
            template : msg,
            buttons: [
                {
                    text: '<b>确定</b>',
                    type: 'button-positive'
                }
            ]
        });
    };
});


module.controller('HuodongShowController',function ($scope, API, $stateParams ,$ionicPopup) {
    console.log(123)
});



